// 平滑滚动到锚点
export function scrollToAnchor(anchorId) {
  if (anchorId === '#') return
  
  const targetElement = document.querySelector(anchorId)
  if (targetElement) {
    window.scrollTo({
      top: targetElement.offsetTop - 80,
      behavior: 'smooth'
    })
  }
}

// 处理导航点击事件
export function handleNavClick(e) {
  const targetId = e.target.getAttribute('href')
  if (targetId && targetId !== '#') {
    e.preventDefault()
    scrollToAnchor(targetId)
  }
}

// 处理移动端导航点击事件（包含关闭菜单逻辑）
export function createMobileNavClickHandler(closeMobileMenu) {
  return (e) => {
    const targetId = e.target.getAttribute('href')
    closeMobileMenu()
    if (targetId && targetId !== '#') {
      e.preventDefault()
      scrollToAnchor(targetId)
    }
  }
}